package com.yourcompany.api.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yourcompany.api.entity.LoginLog;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface LoginLogMapper extends BaseMapper<LoginLog> {
    
    /**
     * 获取用户最近的登录记录
     */
    @Select("SELECT * FROM login_log WHERE user_id = #{userId} AND status = 1 AND is_deleted = 0 ORDER BY login_time DESC LIMIT 1")
    LoginLog getLastLoginLog(@Param("userId") Long userId);
    
    /**
     * 统计用户登录次数
     */
    @Select("SELECT COUNT(*) FROM login_log WHERE user_id = #{userId} AND status = 1 AND is_deleted = 0")
    int countUserLoginTimes(@Param("userId") Long userId);
} 